package leetcode.day;


import java.util.*;

// //590. N 叉树的后序遍历
public class Postorder {

    List<Integer> ans = new ArrayList<>();

    public List<Integer> postorder(Node root) {

        dfs(root);
        return ans;
    }

    private void dfs(Node root) {
        if (root == null) {
            return;
        }
        for (Node child : root.children) {

            dfs(child);
        }

        ans.add(root.val);
    }
}

// Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {
    }

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};

